import { ref } from 'vue'
import {
  getStyleSwiper,
  getRecommendList,
  getSolePlay,
  getNewrstList
} from '@/service/find-music/style-music'

export function InitGetData() {
  // 获取轮播图数据
  const swipers = ref(null)
  getStyleSwiper().then((res: any) => {
    swipers.value = res.banners
  })
  // 获取推荐歌单数据
  const remList = ref([])
  getRecommendList(10).then(
    (res: any) => {
      remList.value = res.playlists
    },
    (err) => {
      console.log('kzj' + err)
    }
  )
  // 获取独家放送数据
  const soleList = ref([])
  getSolePlay().then((res: any) => {
    soleList.value = res.result
  })
  //获取最新音乐数据
  const newestList = ref([[], []])
  getNewrstList().then((res: any) => {
    const allList = res.result
    newestList.value[0] = allList.slice(0, 5)
    newestList.value[1] = allList.slice(5, 10)
  })

  // async function initFn() {
  //   await getStyleSwiper().then((res: any) => {
  //     swipers.value = res.banners
  //   })
  //   await getNewrstList().then((res: any) => {
  //     const allList = res.result
  //     newestList.value[0] = allList.slice(0, 5)
  //     newestList.value[1] = allList.slice(5, 10)
  //   })
  //   await getRecommendList(10).then((res: any) => {
  //     remList.value = res.playlists
  //   })
  //   await getSolePlay().then((res: any) => {
  //     soleList.value = res.result
  //   })
  // }
  // initFn()

  return [swipers, remList, soleList, newestList]
}
